package com.hziee.graduate.ticket.dao;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hziee.graduate.ticket.vo.RoomVO;
import org.apache.ibatis.annotations.Param;
import com.hziee.graduate.ticket.entity.Room;
import org.apache.ibatis.annotations.Select;


public interface RoomDao extends BaseMapper<Room> {

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Room> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Room> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Room> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Room> entities);

    @Select("select r.room_name as roomName, r.room_id as roomId, s.schedule_id as scheduleId, s.start, s.end, c.cinema_name as cinema_Name, c.cinema_address as cinemaAddress, re.name as regionName from t_room r\n" +
            "join t_schedule s on s.room_id = r.room_id\n" +
            "join t_cinema c on s.cinema_id = c.cinema_id\n" +
            "join t_region re on c.region_id = re.id\n" +
            "where movie_id = #{movieId} and date = #{date} and r.cinema_id = #{cinemaId}")
    List<RoomVO> getRoomBySchedule(@Param("movieId") Long movieId,@Param("date") String date, @Param("cinemaId") Long cinemaId);

    @Select("select r.room_name as roomName, m.movie_price as moviePrice, r.room_id as roomId, s.schedule_id as scheduleId, s.start, s.end, c.cinema_name as cinema_Name, c.cinema_address as cinemaAddress, re.name as regionName from t_room r\n" +
            "join t_schedule s on s.room_id = r.room_id\n" +
            "join t_cinema c on s.cinema_id = c.cinema_id\n" +
            "join t_region re on c.region_id = re.id\n" +
            "join t_movie m on s.movie_id = m.movie_id\n" +
            "where m.movie_id = #{movieId} and date = #{date} and r.cinema_id = #{cinemaId} and s.schedule_id = #{scheduleId}")
    RoomVO getARoomBySchedule(@Param("movieId") Long movieId,@Param("date") String date, @Param("cinemaId") Long cinemaId, @Param("scheduleId") Long scheduleId);

//    @Select("select count(*) from t_tickets t\n" +
//            "join t_schedule s on  t.schedule_id = s.schedule_id\n" +
//            "where t.room_id = #{roomId} and s.date = #{date} and check_status = 0")
//    Integer getUnCheckedTicketByDate(@Param("roomId") Long roomId, @Param("date") String date);

    @Select("select count(*) from t_tickets t\n" +
            "join t_schedule s on  t.schedule_id = s.schedule_id\n" +
            "where t.room_id = #{roomId} and s.date = #{date} and check_status = 1")
    Integer getCheckedTicketByDate(@Param("roomId") Long roomId, @Param("date") String date);
}

